/*
 * This file is part of shared-drawing.
 * shared-drawing is free software: you can redistribute it and/or modify it 
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option )
 * any later version. shared-drawing is distributed in the hope that it will
 * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
 * Public License for more details.
 * You should have received a copy of the GNU General Public License along with 
 * shared-drawing. If not, see http://www.gnu.org/licenses/.
 */

package SharedDrawing;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import javax.swing.JPanel;
import primitives.Primitive;

public abstract class BoundingBox 
{
	protected ArrayList<Primitive> m_composingElements;
	protected boolean m_resizable;
	protected Rectangle2D[] m_cornersBox;
	protected JPanel m_container;
	
    /**
     * Function used to initialize the bounding box common attributes
     * @param container: the JPanel containing the objects (useful to set the JTextarea from P_Text)
     * @param x: upper-left corner of the bounding box x-axis
	 * @param y: upper-left corner of the bounding box y-axis
	 * @param width: width of the border/component
	 * @param fill: component filled or not
	 * @param color: main color of the primitive
	 * @param border: border color of the primitive
     */
	public abstract void initShape(JPanel container, int x, int y, int width,
                				   boolean fill, Color color, Color border);
	
	/**
	 * Function used to add the object to the JPanel (useful for P_Text)
	 */
	public void addToPanel(){}
	
	/**
	 * Function used to remove the object from the JPanel (useful for P_Text)
	 */
	public void removeFromPanel(){}
	
	/**
	 * Function used to set the id of the primitives used by the bounding box
	 * Useful to make the correspondence between primitives when using the function toWgContent() and fromWgContent()
	 */
	protected abstract void setElementsId();
	
	/**
	 * Function used to draw the primitives composing the bounding box
	 * @param g: graphic component
	 */
	public abstract void drawComponent(Graphics2D g2);
	
	/**
	 * Function used to draw the object when the drawing mode is "on" and the mouse is dragged
	 * @param x: mouse x-axis
	 * @param y: mouse y-axis
	 */
	public abstract void drawObject(int x, int y);
	
	/**
	 * Funciton used to move a object
	 * @param x: mouse x-axis
	 * @param y: mouse y-axis
	 * @param clickLocation: location of the click in relation with the upper-left corner (and the down-right for the TwoCornerShapes) of the Shape
	 */
	public abstract void moveObject(int x, int y, Coord[] clickLocation);
	
	/**
	 * Function used to save the coordinates of the click in purpose to move the object
	 * @param x: mouse x-axis
	 * @param y: mouse y-axis
	 * @param clickLocation: location of the click in relation with the upper-left corner (and the down-right for the TwoCornerShapes) of the Shape
	 */
	public abstract void setClickLocation(int x, int y, Coord[] clickLocation);
	
	/**
	 * Function used to able to resize a object 
	 * @param x: mouse x-axis
	 * @param y: mouse y-axis
	 * @param cornerType: the corner selected (four corner for a FourCornersShape and two for a TwoCornersShape)
	 */
	public abstract void resizeManager(int x, int y, int cornerType);
	
	/**
	 * Function used to know if the user click on this object
	 * @param x: mouse x-axis
	 * @param y: mouse y-axis
	 * @return true if the mouse is over the element, false else
	 */
	public abstract boolean isOverObject(int x, int y);

	/**
	 * Function used to draw the corner of the object
	 */
	public abstract void drawCorners(Graphics2D g);

	/**
	 * Function used to know if the user click on a corner of this object
	 * @param x: mouse x-axis
	 * @param y: mouse y-axis
	 * @return the corner clicked or 0 if no one has been clicked
	 */
	public abstract int overCorner(double x, double y);

	/**
	 * Function used to position and resize all the elements of the bounding box depending of his own size and position
	 */
	public abstract void setShape();
        
	/**
	 * Function used to transform the current object in a ShapeContent 
	 * @return the ShapeContent with the values depending of the object
	 */
    protected abstract ShapeContent toShapeContent();
    
    /**
	 * Function used set the attributes of the current object from ShapeContent 
	 */
    protected abstract void fromShapeContent(ShapeContent shapeContent);

	public boolean isResizable() {
		return m_resizable;
	}
}
